import {
TOKEN,
LOGIN,
CLOSELOGIN,
LOADING,
GENDER,
UID,
ALERT,
ALERTCLOSE,
MP,
MPCLOSE,
MPOPEN,
MPSTOP,
MPNEXT,
MPDATA
} from './mutation-types.js'

export default {
	//获取token
	[TOKEN](state,value) {
		state.token=value
	},
	//登录
	[LOGIN](state,value) {
		state.token=value
		state.login=true
	},
	//退出登录
	[CLOSELOGIN](state,value) {
		state.login=false
	},
	//加载中
	[LOADING](state,value) {
		state.loading=value
	},
	//选择性别
	[GENDER](state,value) {
		state.gender=value
	},
	//用户uid
	[UID](state,value) {
		state.uid=value.uid
		state.password=value.password
		state.nickname=value.nickname
		state.avatar=value.avatar
		state.square_avatar=value.square_avatar
		state.mb_count=value.mb_count
		state.wallet_balance=value.wallet_balance
		state.gender=value.gender
	},
	//弹窗提示
	[ALERT](state,value) {
		state.alertStatic=value.static
		state.alertStaticTxt=value.txt
	},
	//关闭弹窗提示
	[ALERTCLOSE](state) {
		state.alertStatic=false
	},
	//获取节目数据
	[MPDATA](state,val) {
		state.mpData=val
	},
	//开始播放
	[MP](state,value) {
		state.mpSpan=true
		if(value!=0){
			state.mpPlay=true
			state.mpStatic=true
			state.mpData.map((val)=>{
				if(val.id==value.id){
					state.mpUrl=val.radio_url
					state.mpId=val.id
				}
			})
		}else{
			state.mpPlay=true
			state.mpStatic=true
		}
		
	},
	//开始播放
	[MPSTOP](state) {
		state.mpSpan=true
		state.mpPlay=false
	},
	//关闭播放器
	[MPCLOSE](state) {
		state.mpStatic=false
	},
	//打开播放器
	[MPOPEN](state) {
		state.mpStatic=true
	},
	//上下首播放器
	[MPNEXT](state,value) {
		if(value==1){
			let len=state.mpData.length
			let star=false
			if(state.mpId<len){
				state.mpId+=1
			}else{
				state.mpId=1
			}
			state.mpData.map((val)=>{
				if(val.id==state.mpId){
					state.mpUrl=val.radio_url
				}
			})
			console.log('现在是：'+state.mpId)

		}else{
			let len=state.mpData.length
			let star=false
			if(state.mpId==1){
				state.mpId=len
			}else{
				state.mpId-=1
			}
			state.mpData.map((val)=>{
				if(val.id==state.mpId){
					state.mpUrl=val.radio_url
				}
			})
			console.log('现在是：'+state.mpId)
		}

	},
}
